# learn python

# test if statement
x = 2
if x < 0:
    x = 0;
    print("Negative changed to zero.")
elif x == 0:
    print("zero")
elif x == 1:
    print("single")
else:
    print("more")


# test for statement
list = ['hello', 'world', 'liuling']
for w in list:
    print(w, len(w))

# test range
for i in range(5):
    print(i, sep=', ')
for i in range(len(list)):
    print(i, list[i])
print(range(10)) # range(0, 10)

# break and else
for n in range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print(n, 'equals', x, '*', n // x)
            break;
    else:
        print(n, 'is a prime number')

# continue
for num in range(2, 10):
    if num % 2 ==0:
        print('Found an even number', num)
        continue
    print('Found a number', num)

# define function
def fib(n):
    """Print a Fibonacci series up to n."""
    a, b = 0, 1
    while a < n:
        print(a, end=' ')
        a, b = b, a + b
    print()
fib(2000) # 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,

def fib2(n):
    """Return a list containing the Fibonacci series up to n"""
    result = []
    a, b = 0, 1
    while a < n:
        result.append(a)
        a, b = b, a + b
    return result
print(fib2(100))
